package problem2208;

//2208.将数组和减半的最少操作次数
//https://leetcode.cn/problems/minimum-operations-to-halve-array-sum/

import java.util.Comparator;
import java.util.PriorityQueue;

class Solution {
    public int halveArray(int[] nums) {
        int n = nums.length;
        PriorityQueue<Double> queue = new PriorityQueue<>(new Comparator<Double>(){
            public int compare(Double o1, Double o2) {
                if(o1 == o2) return 0;
                else if(o1 > o2) return -1;
                else return 1;
            }
        });
        double sum = 0;
        for(int x:nums) {
            sum += x;
            queue.add((double)x);
        }
        double count = 0;
        int ret = 0;
        System.out.println(queue);
        while(count < sum/2.0) {
            double x = queue.poll();
            x /= 2;
            count += x;
            queue.add(x); 
            ret ++;
            System.out.println(count);
        }
        return ret;
    }
}